/*
* Created on Tue Jun 13 2023 by Admin
*
* Copyright (c) 2023 shuangdi
*
* description: progress
*
* date: 2025/3/14
*/
<template>
  <div class="root_progress">
    <div class="box">
      <div class="box-inner">
        <div class="inner" style="--per: 0%" id="box">
          <!-- 添加svg波浪 -->
          <svg
              xmlns="http://www.w3.org/2000/svg"
              version="1.0"
              viewBox="0 0 600 140"
              class="box-waves"
          >
            <path
                d="M 0 70 Q 75 20,150 70 T 300 70 T 450 70 T 600 70 L 600 140 L 0 140 L 0 70Z"
            ></path>
          </svg>
          <svg
              xmlns="http://www.w3.org/2000/svg"
              version="1.0"
              viewBox="0 0 600 140"
              class="box-waves"
          >
            <path
                d="M 0 70 Q 75 20,150 70 T 300 70 T 450 70 T 600 70 L 600 140 L 0 140 L 0 70Z"
            ></path>
          </svg>
          <svg
              xmlns="http://www.w3.org/2000/svg"
              version="1.0"
              viewBox="0 0 600 140"
              class="box-waves"
          >
            <path
                d="M 0 70 Q 75 20,150 70 T 300 70 T 450 70 T 600 70 L 600 140 L 0 140 L 0 70Z"
            ></path>
          </svg>
        </div>
      </div>
      <div id="percentText" class="box-text">--%</div>
    </div>
  </div>
</template>

<script setup>
const emit = defineEmits(['finishProcess'])

function getData() {
  const box = document.getElementById("box");
  const text = document.getElementById("percentText");
  let i = 0;
  let timer = null;
  const loading = () => {
    if (i < 100) {
      i++;
      box.style.setProperty("--per", i + "%");
      text.innerHTML = i + "%";
    } else {
      emit('finishProcess')
      i = 0;
      clearInterval(timer);
    }
  };
  loading();
  timer = setInterval(loading, 100);
}

defineExpose({getData})
</script>

<style scoped lang="less">
.root_progress {
  --bg: #222;
  --wave1: #a0edff;
  --wave2: rgba(40, 187, 255, 0.5);
  --wave3: #2084cc;
}

.box {
  width: 650px;
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.box-inner {
  width: 200px;
  height: 200px;
  box-shadow: 0 0 5px 0 #238fdb;
  border-radius: 50%;
  position: relative;
  border: 2px solid transparent;
  background-origin: border-box;
  background-clip: content-box, border-box;
  overflow: hidden;
}

.inner {
  width: 100%;
  height: 100%;
  position: absolute;
  background: #a0edff;
  bottom: calc(-128% + var(--per));
}

.box-waves {
  position: absolute;
  left: 0;
  bottom: 100%;
  width: 200%;
  stroke: none;
}

.box-waves:nth-child(1) {
  fill: var(--wave1);
  transform: translate(-50%, 0);
  z-index: 3;
  /* svg重合有一条线条，将边距设置为负的 */
  margin-bottom: -2px;
  /* 添加动画 */
  animation: wave-move1 1.5s infinite linear;
}

.box-waves:nth-child(2) {
  fill: var(--wave2);
  transform: translate(0, 0);
  z-index: 2;
  animation: wave-move2 3s infinite linear;
}

.box-waves:nth-child(3) {
  fill: var(--wave3);
  transform: translate(-50%, 0);
  z-index: 1;
  /* 添加动画 */
  animation: wave-move1 3s infinite linear;
}

@keyframes wave-move1 {
  100% {
    transform: translate(0, 0);
  }
}

@keyframes wave-move2 {
  100% {
    transform: translate(-50%, 0);
  }
}

.box-text {
  font-size: 30px;
  font-weight: bold;
  width: 80px;
  text-align: center;
  margin-left: 20px;
  color: #7eedff;
}
</style>
